package com.bbzn.user.client.utils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * VO工具类
 */
public class BeanVOUtils {

    //判断所填的对象列表中是否有空值
    public static boolean anyNotNull(final Object... values) {
        return firstNonNull(values) != null;
    }
    public static <T> T firstNonNull(final T... values) {
        if (values != null) {
            for (final T val : values) {
                if (val != null && val != "" ) {
                    return val;
                }
            }
        }
        return null;
    }

    /**
     * 将对象转换成map集合 key为字段名 value为字段值
     * @param obj
     * @return
     * @throws Exception
     */
    public static Map<String, Object> objectToMap(Object obj) throws Exception {
        if(obj == null){
            return null;
        }

        Map<String, Object> map = new HashMap<String, Object>();

        Field[] declaredFields = obj.getClass().getDeclaredFields();
        for (Field field : declaredFields) {
            field.setAccessible(true);
            map.put(field.getName(), field.get(obj));
        }

        return map;
    }
}
